package com.no1ikun.util;

import javax.swing.*;
import java.awt.*;

public class MyJBox  extends JComboBox<String> {
    private String[] opt;
    private int x;
    private int y;
    private int width;
    private int height;
    private Color color;

    private Color textColor;

    public MyJBox(String[] opt, int x, int y, int width, int height,Color color,Color textColor) {
        this.opt = opt;
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.color = color;
        this.textColor = textColor;
        init();
    }
    //获取当前的值
    public String getText(){
        return this.getSelectedItem()+"";
    }
    public int getIndex(){
        return this.getSelectedIndex();
    }
    private  void init(){
        for (String item :this.opt) {
            this.addItem(item);
        }
        //设置but显示的位置
        this.setBounds(x,y,width,height);
        this.setFont(new Font("微软雅黑",Font.BOLD,14));
        //去掉边框
        this.setBorder(null);
        //去掉按钮文字的虚线
        //设置按钮的背景颜色
        this.setBackground(color);
        this.setForeground(textColor);
        this.setVisible(true);
    }
}
